package com.itheima.day13work;



public  class Ticket implements Runnable {

    private int count=100;
//    private Object object=new Object();
    @Override
    public void run() {
        while (true) {
            synchronized (Ticket.class) {
                if (count <= 0) {
                    System.out.println("票卖光了");
                    break;
                } else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Thread thread = Thread.currentThread();//当前线程对象
                    String name = thread.getName();//当前线程的名字
                    count--;
                    System.out.println(name + "在卖票，还剩下" + count + "张");

                }
            }
        }
    }
}
